var currentGadget = bmgadget;

gadget =
{	
	init: function()
	{		
		this.bindState();

		System.Gadget.settingsUI = "settings.html";
		System.Gadget.Flyout.file = "flyout.html";		
    		System.Gadget.onSettingsClosed = gadget.onCloseSettings;    
    		System.Gadget.onUndock = gadget.undock;
    		System.Gadget.onDock = gadget.dock;  		
		
    		currentGadget.init();    		
    		currentGadget.load();
	},	
	bindState: function()
	{
		if(System.Gadget.docked) 
    		{
        		this.dock();
    		} 
    		else
    		{
        		this.undock(); 
    		}
	},
	refresh: function()
	{
		currentGadget.config.read();
		currentGadget.load();				
	},
	onCloseSettings: function(event)
	{
		if (event.closeAction == event.Action.commit)
    		{
    			gadget.refresh(); 
    		}
	},
	undock: function()
	{
		with(document.body.style)
        		width=360, 
        		height=280;

    		with(gadgetbg.style)
        		width=360, 
        		height=280;
    
    		docked.style.display = 'none';
    		undocked.style.display = 'block';
        
    		gadgetbg.src="url(img/undockbg.png)";   
    		currentGadget.undocked();
	},
	dock: function()
	{
		with(document.body.style)
        		width=130,
        		height=120;

    		with(gadgetbg.style)
        		width=130,
        		height=100;
    
    		docked.style.display = 'block';
    		undocked.style.display = 'none';
    
    		gadgetbg.src="url(img/dockbg.png)";
    		currentGadget.docked();
	}
}

gadgetsettings =
{
	init: function()
	{
		System.Gadget.onSettingsClosing = gadgetsettings.save;			
		
		currentGadget.config.read();		
		currentGadget.settings.display();		
	},
	save: function(event)
	{			
		if (event.closeAction == event.Action.commit)
		{
			currentGadget.settings.update();		
			currentGadget.config.save();
		}
		else if(event.closeAction == event.Action.cancel)
		{
		}
		
		event.cancel = false;		
	}
}

gadgetflyout =
{
	init: function()
	{
		System.Gadget.Flyout.onShow = gadgetflyout.onShow;
            	System.Gadget.Flyout.onHide = gadgetflyout.onHide;
		currentGadget.config.read();
		currentGadget.load();		
	},
	keypress: function()
	{	
		currentGadget.flyout.keypress();
	},
	showFlyout: function()
	{				
            	System.Gadget.Flyout.show = true;
	},
	onShow : function()
	{		
		currentGadget.flyout.display();		
	},
	onHide : function()
	{
	}
}
